package com.centling.bluecollar.login.DAO;

import java.util.ArrayList;  
import java.util.Iterator;  
import java.util.List;  
import java.util.Set;  
  



import org.hibernate.Query;  
import org.hibernate.Session;  
import org.springframework.stereotype.Repository;  

import com.centling.bluecollar.login.entity.Roles;
import com.centling.bluecollar.login.entity.User;
  
  
@Repository  
public class UserDAO extends BaseDAO implements IUserDAO {  
  
    @Override  
    public void save(User user) {  
    }  
  
    @Override  
    public void delete(User user) {  
        // TODO Auto-generated method stub  
  
    }  
  
    @Override  
    public User findUserById(String id) {  
        // TODO Auto-generated method stub  
        return null;  
    }  
  
    @Override  
    public User findUserByUsername(String username) {  
        // TODO Auto-generated method stub  
        return null;  
    }  
  
    @Override  
    public List findByProperty(String propertyName, Object value) {  
        // TODO Auto-generated method stub  
        return null;  
    }  
  
    public User getUserByName(String username) {  
        Session s = getSession();  
        Query query = s.createQuery("from User as u where u.username = ?");  
        query.setString(0, username);  
        User user = (User) query.uniqueResult();  
        return user;  
    }  
  
    public List<String> loadUserAuthoritiesByName(String username) {  
        User user = this.getUserByName(username);  
        if (user != null) {  
            Set<Roles> roles = user.getRoles();  
            List<String> auth = new ArrayList<String>();  
            Iterator<Roles> it = roles.iterator();  
            while (it.hasNext()) {  
                auth.add(((Roles) it.next()).getRolename());  
            }  
            return auth;  
        } else {  
            return null;  
        }  
    }  
}  